#include "pool.h"
#include <pthread.h>
#include <stdio.h>

static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;

void add_task(void *argv)
{
    int *p_num = argv;
    pthread_mutex_lock(&lock);
    *p_num += 1;
    pthread_mutex_unlock(&lock);
}

int main(int argc, char const *argv[])
{
    int num = 0;
    Task task = {
        .task_func = add_task,
        .argv = &num};
    
    int result = pool_init(10);
    if (result < 0)
    {
        printf("线程池初始化失败\n");
        return -1;
    }

    for (int i = 0; i < 20000; i++)
    {
        int result = pool_registerTask(&task);
        if (result < 0)
        {
            perror("register_task");
        }
    }

    while (num < 20000)
        ;

    pool_close();

    printf("num: %d\n", num);

    return 0;
}
